<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../../js/react.development.js"></script>
    <!-- 用于支持react操作DOM -->
    <script type="text/javascript" src="../../js/react-dom.development.js"></script>
    <!-- 用于将jsx转为js -->
    <script type="text/javascript" src="../../js/babel.min.js"></script>
    <!-- 用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="../../js/prop-types.js"></script>
</head>
<body>
    <div id="test"></div>

    <script type="text/babel">
        class MyComponent extends React.Component{
            state = {
                username: "",
                password: ""
            }
            saveFormData = (dataType, event)=>{
                this.setState({[dataType]: event.target.value})
            }
            render(){
                return (
                    <form onSubmit={this.show}>
                        <input onChange={()=>this.saveFormData("username")} type="text" placeholder="账号"/>
                        <input onChange={()=>this.saveFormData("password")} type="password" placeholder="密码"/>
                        <button>展示</button>
                    </form>
                )
            }
            show = (event)=>{
                event.preventDefault()  // 阻止表单提交
                const {username,password} = this.state
                alert(`账号是：${username}，密码是：${password}`)
            }
        }
        
        let p ={}
        ReactDOM.render(<MyComponent {...p}/>,document.getElementById("test"))
    </script>
</body>
<style>
</style>
</html>